package lc.模拟;

import java.util.ArrayList;
import java.util.List;

/**
 * 赎金信
 *
 * @author yang
 * @date 2022/1/2
 */
public class 赎金信 {

    public boolean canConstruct(String ransomNote, String magazine) {

/*        int flag = ransomNote.length();
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < ransomNote.length(); i++) {
            list.add(ransomNote.charAt(i));
        }
        for (int i = 0; i < magazine.length(); i++) {
            if (list.contains(magazine.charAt(i))) {
                list.remove((Character) magazine.charAt(i));
                flag--;
            }
        }
        return flag == 0;*/

        int[] cut = new int[26];
        for (char c : magazine.toCharArray()) {
            cut[c - 'a']++;
        }
        for (char c : ransomNote.toCharArray()) {

            if (--cut[c - 'a'] < 0) return false;
        }
        return true;

    }

    public static void main(String[] args) {
        赎金信 b = new 赎金信();
        boolean b1 = b.canConstruct("aa", "aab");
        System.out.println(b1);
    }
}
